using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Http;
using System.Web.Http;
using System.Web.Http.Controllers;
using System.Web.Http.Hosting;
using System.Web.Http.Routing;
using System.Web.Routing;
using EmployeesManager.Controllers;
using EmployeesManager.Poco;
using EmployeesManagerDataAccessContracts;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Moq;

namespace ManagerUnitTests
{
    public static class TestHelpers
    {
        public static IQueryable<Employee> ValidEmployeesList()
        {
            return new List<Employee>
                       {
                           new Employee
                               {
                                   Id=1,
                                   Age = 43,
                                   Name = "Hary",
                                   Salary = 20000,
                                   Title = "CEO"
                               },
                           new Employee
                               {
                                   Id = 2,
                                   Age = 35,
                                   Name = "Thomas",
                                   Salary = 5000,
                                   Title = "Sales Manager",
                                   ManagerId= 1,
                               },
                           new Employee
                               {
                                   Id = 3,
                                   Age = 23,
                                   Name = "Henry",
                                   Salary = 12000,
                                   Title = "Sales Person",
                                   ManagerId = 2,
                               },
                           new Employee
                               {
                                   Id = 4,
                                   Age = 33,
                                   Name = "John",
                                   Salary = 8000,
                                   Title = "Technical Manager",
                                   ManagerId = 1,
                               },
                           new Employee
                               {
                                   Id = 5,
                                   Age = 31,
                                   Name = "Steve",
                                   Salary = 5000,
                                   Title = "Technical Lead",
                                   ManagerId = 4,
                               }
                       }.AsQueryable();
        }
        public static EmployeesController SetupControllerForTests(Mock<IRepository<Employee>> employeesRepo)
        {
            var config = new HttpConfiguration();
            var request = new HttpRequestMessage(HttpMethod.Post, "http://localhost/api/employees");
            request.RequestUri = new Uri("http://localhost/api/employees");
            var route = config.Routes.MapHttpRoute("DefaultApi", "api/{controller}/{id}");
            var routeData = new HttpRouteData(route, new HttpRouteValueDictionary { { "controller", "employees" } });
            var employeesController = new EmployeesController(employeesRepo.Object)
                                          {
                                              ControllerContext = new HttpControllerContext(config, routeData, request),
                                              Request = request
                                          };
            employeesController.Request.Properties.Add(HttpPropertyKeys.HttpRouteDataKey, routeData);

            employeesController.Request.Properties[HttpPropertyKeys.HttpConfigurationKey] = config;

            return employeesController;
        }

    }
}